<template>
	<view style="padding: 20px;">
		<view style="font-weight: bold;font-size: 24px;padding: 100px 0 100px 0;">亲爱的主人，欢迎回家</view>
		<view class="uni-common-mt" style="">
			<view class="uni-form-item uni-column">
				<input style="padding: 10px;border-bottom: 1px solid #eee;" class="uni-input" v-model="account" focus
					placeholder="请输入账号" />
			</view>
			<view class="uni-form-item uni-column">
				<input type="password" style="padding: 10px;border-bottom: 1px solid #eee;" class="uni-input" v-model="password" focus
					placeholder="请输入密码" />
			</view>
			<view class="uni-form-item uni-column" style="margin-top: 10px;">
				<checkbox-group @change="read">
					<label style="font-size: 14px;color: gray;">
						<checkbox style="transform:scale(0.7)" value="1" :checked=is_read />我已阅读<view style="display: inline-block;">《用户协议》</view>
					</label>
				</checkbox-group>
			</view>
			<button style="margin-top: 40px;" type="primary" @click="login">立即登录</button><!-- 这种写法只有h5平台支持，不跨端，不推荐使用 -->
			<view style="text-align: right;margin-top: 10px;">
				<view class="txt">忘记密码</view>
				<view @click="register()" class="txt">注册账号</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				account: '',
				password: '',
				is_read: false,
			}
		},
		onLoad() {

		},
		methods: {
			read(e) {
				this.is_read = !this.is_read;
			},
			login() {
				if (!this.is_read) {
					uni.showToast({
						title: '请确定已阅读协议',
						duration: 2000,
						icon: 'none',
					})
					return;
				}
				if (this.account == '' || this.password == '') {
					return;
				}
				this.$api.postSignin({account: this.account, password: this.password})
				.then(res => {
					if (res.meta.code == '000') {
						uni.setStorageSync('uid', res.data.id);
						uni.setStorageSync('username', res.data.username);
						uni.setStorageSync('community_name', res.data.community_name);
						uni.setStorageSync('community_id', res.data.community_id);
						uni.setStorageSync('building_number_id', res.data.building_number_id);
						uni.setStorageSync('house_id', res.data.house_id);
						uni.setStorageSync('unit_id', res.data.unit_id);
						uni.setStorageSync('proprietor_id', res.data.proprietor_id);
						uni.setStorageSync('muid', res.data.muid);
						uni.setStorageSync('avatar', res.data.avatar);
						uni.setStorageSync('address', res.data.address);
						uni.setStorageSync('mobile_number', res.data.mobile_number);
						uni.setStorageSync('validity_day', res.data.validity_day);
						uni.setStorageSync('status', res.data.status);
						uni.setStorageSync('is_login', 1);
						uni.redirectTo({
							url: '/pages/index/index'
						});
					}
				}).catch(e => {
					
				})
			},
			register() {
				uni.navigateTo({
					url: '/pages/user/signup'
				})
			},
		}
	}
</script>

<style>
	
	.txt {
		display: inline-block;
		position: relative;
		font-size: 14px;
		padding: 0 20px;
		color: gray;
	}
	.txt:nth-child(2) {
		padding-right: 0;
	}
	
	.txt:nth-child(1)::after {
		content: "";
		width: 1px;
		height: 80%;
		position: absolute;
		top: 10%;
		right: 0;
		background: gray;
	}
</style>
